require "xmlrpc/client"

class MetaWeblogClient < XMLRPC::Client
  def initialize(username, password, host, url)
    super(host, url)
    @username = username;
    @password = password;
  end

  def newPost(post, publish)
    ok, param = call2("metaWeblog.newPost", "0", "#{@username}", "#{@password}", post, publish)
    return ok, param
  end

  def getUserBlogs()
    ok, param = call2("blogger.getUsersBlogs", "0", "#{@username}", "#{@password}")
    return ok, param
  end

  def deletePost(postid)
    ok, param = call2("blogger.deletePost", "0", postid, "#{@username}", "#{@password}")
    return ok, param
  end

  def editPost(post, publish)
    ok, param = call2("metaWeblog.editPost", postid, "#{@username}", "#{@password}")
    return ok, param
  end

  def getCategories(blogid)
    ok, param = call2("metaWeblog.getCategories", blogid, "#{@username}", "#{@password}")
    return ok, param
  end

  def getPost(postid)
    ok, param = call2("metaWeblog.getPost", postid, "#{@username}", "#{@password}")
    return ok, param
  end

  def getRecentPosts(blogid, numberOfPosts)
    ok, param = call2("metaWeblog.getRecentPosts", blogid, "#{@username}", "#{@password}")
    return ok, param
  end

  def newMediaObject(blogid, file)
    ok, param = call2("metaWeblog.newMediaObject", blogid, "#{@username}", "#{@password}", file)
    return ok, param
  end

  def newCategory(blog_id, category)
    ok, param = call2("metaWeblog.getCategories", blogid, "#{@username}", "#{@password}", category)
    return ok, param
  end

end
